import { Component } from '@angular/core';
import { NavController, NavParams,ToastController } from 'ionic-angular';
import { Dialogs } from '@ionic-native/dialogs';
import { Camera } from '@ionic-native/camera';
import { Http, Response,Headers, RequestOptions } from '@angular/http';
import { HttpServiceProvider } from '../../providers/http-service/http-service';
import { UdpServiceProvider } from '../../providers/udp-service/udp-service';
import { MqttServiceProvider } from '../../providers/mqtt-service/mqtt-service';
/**
 * Generated class for the TestPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
@Component({
  selector: 'page-test',
  templateUrl: 'test.html',
})

export class TestPage {

  public base64Image: string;

  public myMessage;

  udpData: any;


  listData: Object;
  //data:any = {};

  constructor(public navCtrl: NavController, public navParams: NavParams,
    public toastCtrl: ToastController,private dialogs: Dialogs,
    private camera: Camera,
    private http: Http,
    private httpServiceProvider: HttpServiceProvider,
    private udpServiceProvider:UdpServiceProvider,
    private mqttServiceProvider:MqttServiceProvider
    ) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad TestPage');
  }
  ionViewWillEnter(){

    console.log('ionViewWillEnter TestPage');
      }
      
  httpTestReq()
  {
    let link = 'http://zhongqing.iotplc.cn/Login/login';
    let body = 'account=' + 'zhuqiyun' + '&password=' + '123456';

    this.httpServiceProvider.post(link,body).then(data=>{console.log(data)});
  }

  udp_create() {

    this.udpServiceProvider.UDPCreate().then(
        data=>{
          this.udpData=data;
          this.udpServiceProvider.UDPBind(this.udpData.socketId);
          this.udpServiceProvider.UDPAddEvent();
        }
    );
  }

  udp_send() {
    this.udpServiceProvider.UDPSend(this.udpData.socketId,this.udpServiceProvider.str2ab("qweqweqweqwe12312323"),'192.168.1.100',60000);
  }



  presentToast() {
    let toast = this.toastCtrl.create({
      message: 'toast test OK',
      duration: 3000
    });
    toast.present();
    console.log('toast 测试成功');
    this.dialogs.beep(1);
  }

  takePicture(){
        this.camera.getPicture({
        destinationType: this.camera.DestinationType.DATA_URL,
        targetWidth: 1000,
        targetHeight: 1000
    }).then((imageData) => {
      // imageData is a base64 encoded string
        this.base64Image = "data:image/jpeg;base64," + imageData;
    }, (err) => {
        console.log(err);
    });
  }

  isDanger: boolean = true;
  isSecondary: boolean = false;
  isRound: boolean = true;
  isOutline: boolean = false;
  isClear: boolean = true;
  myColor: string = 'secondary';
  myColor2: string = 'dark';


}


